Add GenericFormDataValidator2 that doesn't take DataType in constructor#547
Open
Add GenericFormDataValidator2 that doesn't take DataType in constructor#547
Conversation
|
…taType. Keep the old GenericFormDataValidator for backwards compatibility.
7e0e6c8 to
6477b1f
Compare
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.






GenericFormDataValidator<TModel>is a (currently undocumented) convenience abstract class for implementingIFormDataValidator. The benefit is thatHasRelevantChangesandValidateFormDatahas a signature ofTModelinstead ofobjectand the helper methodCreateValidationIssuethat takes an expression (aka linq) instead of providing the field the issue relates to as a string. In additionValidateFormDatadoes not return a list of issues, but instead you register them withAddValidationIssueandCreateValidationIssue.The previous version of this abstract class defined the
DataTypeproperty and to ensure that users actually set this property, it was a required parameter in the constructor. Today I realised that it was hard to read and understand how that magic string ended up in thebase()call, and that an abstract class can declare an abstract property so that inheriting classes is required to implement the property. I think this results in much prettier code.The new way is almost the same as when you implement the
IFormDataValidatorinterface directly (needs theoverridekeyword because of the abstract class)Breaking change, alternatives?
This is a breaking change which will cause those apps that has started to use
GenericFormDataValidator<TModel>. As it is not documented, I think that would be very few cases.Add obsolete message, to better explain the change
We can improve the error message by adding the following constructors.
Create a new abstract class
As this is just a utility class, we could potentially just add a new one with a new name and the slightly changed semantics. This will ensure that no direct changes will be needed until the old (obsolete) version is removed in v9. Good suggestions for names would be very welcome. See suggestion here
Related Issue(s)
Verification
Documentation